window.addEvent("domready", function(){
	var processing = $("processing");
	ProcessingAS.onLoad = function () {
		processing.start();
	};
	
	ProcessingAS.onResize = function (w, h) {
		processing.height = h;
		processing.width = w;
	};

	$("p").addEvent("click", function(){
		var code = $("code").get("value");
		var images = new Array();
		var imagesSrc = code.match(/loadImage\(\"?.+\"\);/gi); 		
		if (imagesSrc) {
			imagesSrc.each(function(image){
				var r = image;
				r = r.replace("loadImage(\"", "");
				r = r.replace("\");", "");
				images.push([r,r]);
			});
		}
		processing.run(code, images);
	});

});
